package com.geega.web.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2023/3/20 13:48
 */
@Slf4j
@RestController
@Api
public class WebController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @PostMapping("getErrorList")
    public List<Object> getErrorList() {
        return jdbcTemplate.queryForList("select data from sys_data").stream().map(map -> map.get("data")).collect(Collectors.toList());
    }

    @PostMapping("reportData")
    public void reportData(@RequestBody String data) {
        log.info("上报数据：{}", data);
        jdbcTemplate.update("insert into sys_data(data) values(?)", data);
    }
}
